package com.ruoyi.web.controller.showreport;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.report.domain.ReportShowtableColumn;
import com.ruoyi.report.service.IReportShowtableColumnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 *  报告展示列维护Controller
 * 
 * @author wry
 * @date 2023-06-20
 */
@RestController
@RequestMapping("/showreport/showtablecolumn")
public class ReportShowtableColumnController extends BaseController
{
    @Autowired
    private IReportShowtableColumnService reportShowtableColumnService;

    /**
     * 查询 报告展示列维护列表
     */
    @PreAuthorize("@ss.hasPermi('showreport:showtablecolumn:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReportShowtableColumn reportShowtableColumn)
    {
        startPage();
        List<ReportShowtableColumn> list = reportShowtableColumnService.selectReportShowtableColumnList(reportShowtableColumn);
        return getDataTable(list);
    }

    /**
     * 导出 报告展示列维护列表
     */
    @PreAuthorize("@ss.hasPermi('showreport:showtablecolumn:export')")
    @Log(title = " 报告展示列维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReportShowtableColumn reportShowtableColumn)
    {
        List<ReportShowtableColumn> list = reportShowtableColumnService.selectReportShowtableColumnList(reportShowtableColumn);
        ExcelUtil<ReportShowtableColumn> util = new ExcelUtil<ReportShowtableColumn>(ReportShowtableColumn.class);
        util.exportExcel(response, list, " 报告展示列维护数据");
    }

    /**
     * 获取 报告展示列维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('showreport:showtablecolumn:query')")
    @GetMapping(value = "/{columnId}")
    public AjaxResult getInfo(@PathVariable("columnId") Long columnId)
    {
        return success(reportShowtableColumnService.selectReportShowtableColumnByColumnId(columnId));
    }

    /**
     * 新增 报告展示列维护
     */
    @PreAuthorize("@ss.hasPermi('showreport:showtablecolumn:add')")
    @Log(title = " 报告展示列维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReportShowtableColumn reportShowtableColumn)
    {
        if (!reportShowtableColumnService.checkColumnSortUnique(reportShowtableColumn))
        {
            return error("新增列'" + reportShowtableColumn.getShowColumnName() + "'失败，列序号已存在");
        }
        reportShowtableColumn.setCreateBy(getUsername());
        return toAjax(reportShowtableColumnService.insertReportShowtableColumn(reportShowtableColumn));
    }

    /**
     * 修改 报告展示列维护
     */
    @PreAuthorize("@ss.hasPermi('showreport:showtablecolumn:edit')")
    @Log(title = " 报告展示列维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReportShowtableColumn reportShowtableColumn)
    {
        if (!reportShowtableColumnService.checkColumnSortUnique(reportShowtableColumn))
        {
            return error("修改列'" + reportShowtableColumn.getShowColumnName() + "'失败，列序号已存在");
        }
        reportShowtableColumn.setUpdateBy(getUsername());
        return toAjax(reportShowtableColumnService.updateReportShowtableColumn(reportShowtableColumn));
    }

    /**
     * 删除 报告展示列维护
     */
    @PreAuthorize("@ss.hasPermi('showreport:showtablecolumn:remove')")
    @Log(title = " 报告展示列维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{columnIds}")
    public AjaxResult remove(@PathVariable Long[] columnIds)
    {
        return toAjax(reportShowtableColumnService.deleteReportShowtableColumnByColumnIds(columnIds));
    }
}
